package br.com.expositor.apresentacao.administracao.componente.menu;

import java.util.List;

import org.apache.wicket.markup.html.IHeaderResponse;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;
import org.apache.wicket.request.resource.PackageResourceReference;

import br.com.expositor.apresentacao.administracao.componente.infra.ComponenteGenerico;
import br.com.expositor.negocios.entidade.ItemMenu;

public class ComponenteMenu extends ComponenteGenerico {

	private static final long serialVersionUID = 3456718744961480313L;

	private List<ItemMenu> itens;

	public ComponenteMenu(String id) {
		super(id);
	}

	public ComponenteMenu(String id, List<ItemMenu> itens) {
		super(id);
		this.itens = itens;
		this.montarComponente();
	}

	@Override
	public void montarComponente() {
		this.montarMenu(this.itens);
	}

	private void montarMenu(List<ItemMenu> itens) {

		ListView<ItemMenu> itensMenu = new ListView<ItemMenu>("menuDrop", itens) {

			private static final long serialVersionUID = -8754579684252801978L;

			@Override
			protected void populateItem(ListItem<ItemMenu> item) {
				ItemMenu itemMenu = item.getModelObject();
				item.add(new Label("nome", itemMenu.getNome()));
				item.add(new ComponenteItemMenu("subMenuDrop",
						(List<ItemMenu>) itemMenu.getItensFilhos()));
			}
		};
		this.add(itensMenu);
	}

	@Override
	public void renderHead(IHeaderResponse response) {

		response.renderJavascriptReference(new PackageResourceReference(
				ComponenteMenu.class, "js/superfish.js"));
		response.renderJavascriptReference(new PackageResourceReference(
				ComponenteMenu.class, "js/hoverIntent.js"));

		response.renderCSSReference(new PackageResourceReference(
				ComponenteMenu.class, "css/superfish-vertical.css"));
		response.renderCSSReference(new PackageResourceReference(
				ComponenteMenu.class, "css/superfish-navbar.css"));
		response.renderCSSReference(new PackageResourceReference(
				ComponenteMenu.class, "css/superfish.css"));

	}
}
